package com.itjason.controller;


import com.itjason.dto.CommentDTO;
import com.itjason.dto.DeleteDynamicDTO;
import com.itjason.dto.DynamicDTO;
import com.itjason.exceptionhandler.ResponseException;
import com.itjason.po.Comments;
import com.itjason.po.Dynamics;
import com.itjason.service.DynamicsService;
import com.itjason.vo.DynamicVO;
import com.itjason.vo.DynamicsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("社区的管理")
@RestController
@RequestMapping("wx/dynamic")
public class WxDynamicController {

    @Autowired
    private DynamicsService dynamicsService;

    @ApiOperation("发布动态")
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "dynamicDTO",value = "前端数据接收模型")
    })
    @PostMapping("/add")
    public ResponseException add(@RequestBody DynamicDTO dynamicDTO){
        return dynamicsService.addDynamic(dynamicDTO);
    }

    @ApiOperation("评论动态")
    @PostMapping("comment")
    public ResponseException addComment(@RequestBody CommentDTO commentDTO){
        return dynamicsService.addComment(commentDTO);
    }

    @ApiOperation("删除动态和删除个人评论")
    @GetMapping("deleteDynamic")
    public ResponseException deleteDynamic(DeleteDynamicDTO dynamicDTO){
        return dynamicsService.deleteDynamic(dynamicDTO);
    }

    @ApiOperation("全部社区动态")
    @GetMapping("getDynamics")
    public DynamicsVO getDynamics(){
        return dynamicsService.getDynamics();
    }

    @ApiOperation("个人用户社区动态")
    @GetMapping("getDynamicsAboutUser")
    public List<DynamicVO> getDynamicsAboutUser(@RequestParam("userId") Integer userId){
        return dynamicsService.getDynamicByUserId(userId);
    }

    @ApiOperation("动态id获取评论")
    @GetMapping("/getCommentsByDynamicId")
    public List<Comments> getCommentsByDynamicId(@RequestParam("dynamicId") Integer dynamicId){
        return dynamicsService.getDynamicsAboutComments(dynamicId);
    }

}
